package com.cgx.controller;

import com.cgx.entity.Category;
import com.cgx.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chenguanxin
 * @date 2020-07-22 21:18
 */
@Controller
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/init")
    @ResponseBody
    public Object init(){
        Map<String, Object> result = new HashMap<>();
        try {
            List<Category> list = categoryService.initTree();
            result.put("data",list);
            result.put("success",true);
            result.put("code",0);
            result.put("msg","获取成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.put("success",false);
            result.put("code",500);
            result.put("msg","获取失败");
        }
        return result;
    }
}
